package com.gxm.base.jdk8.function;

import org.junit.Test;

import java.util.function.Function;

public class Demo {
    @Test
    public void Demo1(){
        Function<Integer, Integer> test = i -> i+1;
        test.apply(5);
        System.out.println(test.apply(5));
    }

    @Test
    public void Demo2(){
        Function<Integer,Integer> test1=i->i+1;
        Function<Integer,Integer> test2=i->i*i;
        System.out.println(calculate(test1,5));
        System.out.println(calculate(test2,5));
    }

    public static Integer calculate(Function<Integer,Integer> test,Integer number){
        return test.apply(number);
    }

    @Test
    public void Demo3(){
        Function<Integer,Integer> A=i->i+1;
        Function<Integer,Integer> B=i->i*i;
        System.out.println("F1:"+B.apply(A.apply(5)));
        System.out.println("F2:"+A.apply(B.apply(5)));
    }

    @Test
    public void Demo4(){
        Function<Integer,Integer> A=i->i+1;
        Function<Integer,Integer> B=i->i*i;
        System.out.println("F1:"+B.apply(A.apply(5)));
        System.out.println("F1:"+B.compose(A).apply(5));
        System.out.println("F2:"+A.apply(B.apply(5)));
        System.out.println("F2:"+B.andThen(A).apply(5));
    }
}
